package com.tuanzi.loan.web.bean.family;

import com.tuanzi.loan.business.entity.family.LoanNewCreditCardProgress;
import com.tuanzi.loan.business.service.family.LoanNewCreditCardProgressService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.family.LoanNewCreditCardProgressRequest;
import com.tuanzi.loan.vo.response.family.LoanNewCreditCardProgressResponse;
import com.tuanzi.loan.web.configuration.JSFListingBean;
import com.tuanzi.loan.web.lazy.family.LoanNewCreditCardProgressListLazyDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import java.util.Objects;

/**
 * User: liangZongXi
 * Create time: 10:52 2018/9/20
 * Description:
 */
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class LoanNewCreditCardProgressListBean extends JSFListingBean<LoanNewCreditCardProgressRequest, LoanNewCreditCardProgressResponse>{
    private static final long serialVersionUID = -854961850598766216L;

    @Autowired
    private LoanNewCreditCardProgressService loanNewCreditCardProgressService;

    @PostConstruct
    private void init(){
        initLazyDataModel();
    }

    private void initLazyDataModel(){
        $ = new LoanNewCreditCardProgressRequest();
        lazyDataModel = new LoanNewCreditCardProgressListLazyDataModel($);
    }

    public void onRest(){
        initLazyDataModel();
    }

    public String add(){
        return redirect("/views/family/credithousekeeper/credit-card-progress-info.xhtml");
    }

    public String toInfo(Integer id){
        return redirect("/views/family/credithousekeeper/credit-card-progress-info.xhtml?id="+id);
    }

    public void onOpByStatus(Integer id, Integer status){
        if(id == null){
            initLazyDataModel();
            return;
        }

        if(status == null){
           addErrorMessage("请输入变换的状态");
           return;
        }

        LoanNewCreditCardProgress one = loanNewCreditCardProgressService.findOne(id);
        if(Objects.isNull(one)){
            initLazyDataModel();
            return;
        }

        one.setStatus(status);
        loanNewCreditCardProgressService.saveOrUpdate(one);

        initLazyDataModel();
        addSuccessfullyMessage();

    }



}
